class TimeUnit < ActiveRecord::Base
  has_many :terms
  has_many :equivalent_time_units,
    :class_name => 'TimeUnit',
    :finder_sql => 'SELECT t.* FROM time_units AS t, equivalent_time_units AS te WHERE t.id = te.equivalent_to_id AND te.time_unit_id = #{id}',
    :counter_sql => 'SELECT count(*) from equivalent_time_units AS te WHERE te.time_unit_id = #{id}'

  validates_presence_of :name, :abbreviation, :plural
  validates_uniqueness_of :name, :plural
end
